<style type="text/css">
    .layui-table-body{overflow-x:auto;}
    .layui-table-cell{font-size:12px;}
</style>
<table id="dataTable"></table>

<script type="text/html" id="statusTpl">
    <input type="checkbox" name="status" value="{{ d.status }}" lay-skin="switch" lay-filter="switchStatus" lay-text="正常|关闭" {{ d.status == 1 ? 'checked' : '' }} data-href="{:url('status')}?id={{ d.id }}">
</script>
<script type="text/html" title="操作按钮模板" id="buttonTpl">
    <a href="{:url('edit')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe-pop"  hisi-data="{width: '550px', height: '500px', title: '修改'}">修改</a><a href="{:url('del')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-danger j-tr-del">删除</a>
</script>
{include file="system@block/layui" /}
<script id="toolbar" type="text/html">
    <a href="{:url('add')}?pid={$pid}" class="layui-btn layui-btn-normal layui-btn-sm hisi-iframe-pop" hisi-data="{width: '550px', height: '500px', title: '添加'}">&nbsp;添加</a>
</script>
<script type="text/javascript">
    layui.use(['table'], function() {
        var table = layui.table;
        table.render({
            elem: '#dataTable'
            ,url: '{:url()}'+'?pid='+{$pid} //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter']
            ,cols: [[ //表头
                {type:'checkbox'}
                ,{field: 'id', title: 'ID'}
                ,{field: 'name', title: '产品名称',templet:function(d){
                    return d.has_product.name
                }}
                ,{field: 'category_number', title: '数量'}
                ,{field: 'is_volume', title: '是否分解',templet:function(d){
                    if(d.is_volume == 1){
                        return '<span style="color:red">分解使用</span>'
                    }else{
                        return '<span style="color:green">不分解</span>'
                    }
                }}
                ,{field: 'unit', title: '单位',templet:function(d){
                    if(d.is_volume == 2){  // 是
                        return d.has_product.unit
                    }else if(d.is_volume == 1){
                        return d.has_product.decomposition
                    }
                }}
                ,{title: '操作', width: 120, templet: '#buttonTpl'}
            ]]

        });
    });
</script>
